#ifndef INDEXBUFFER_H
#define INDEXBUFFER_H

#include "GpuBuffer.h"

namespace Cvekas {

class GpuBufferManager;

/// Index buffer
class IndexBuffer : public GpuBuffer
{
public:
	/// Constructor. You shouldn't construct IndexBuffer yourself, GpuBufferManager does this.
	IndexBuffer(ResourceId id, D3DDevicePtr _device, const std::string& name, 
		bool sixteen_bits, uint indice_count, bool is_dynamic);

	/// Destructor
	virtual ~IndexBuffer();

	/// Is index buffer locked?
	virtual bool isLocked() const;

	/// Locks index buffer. Throws Exception if buffer is already locked.
	/// \param read_only Pass true if no writing to locked buffer will be done, it improves performance.
	virtual LockedBuffer lock(bool read_only);
	/// Unlocks locked buffer. Throws Exception if buffer is not locked.
	virtual void unlock();

	/// Returns number of indices in buffer
	int getIndexCount() const;
	/// Returns true if indices is 16 bit and false if 32 bit
	bool isSixteenBits() const;

	/// Returns pointer to IDirect3DIndexBuffer9
	IDirect3DIndexBuffer9* getD3DIndexBuffer() const;

	/// You shouldn't call this
	virtual void onDeviceLost();
	/// You shouldn't call this
	virtual void onDeviceReset();

private:
	void create();

	const uint indice_count;
	const bool sixteen_bits;
	bool is_locked;
	DWORD usage;
	IDirect3DIndexBuffer9* index_buffer;
};

typedef boost::shared_ptr<IndexBuffer> IndexBufferPtr;

} // namespace

#endif